<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .div1 {
      width: 200px;
      height: 200px;
      background-color: red;
    }
    .div2 {
      width: 150px;
      height: 150px;
      background-color: blue;
    }
    .div3 {
      width: 100px;
      height: 100px;
      background-color: yellow;
    }
  </style>
</head>
<body>
  <div id="app">
    <p>修饰符</p>
    <p>1. 事件修饰符</p>
    <p>stop:阻止冒泡</p>
    <div class="div1" @click="clickHandler('div1')">
      <div class="div2" @click.stop="clickHandler('div2')">
        <div class="div3" @click="clickHandler('div3')"></div>
      </div>
    </div>
    <p>prevent：阻止默认事件</p>
    <div class="div1" @contextmenu.prevent="showMenu">点击右键</div>
    <p>capture:在冒泡阶段优先执行</p>
    <div class="div1" @click.capture="clickHandler('div1')">
      <div class="div2" @click="clickHandler('div2')">
        <div class="div3" @click="clickHandler('div3')"></div>
      </div>
    </div>
    <p>self：只执行由自己触发的函数</p>
    <div class="div1" @click.self="clickHandler('div1')">
      <div class="div2" @click="clickHandler('div2')">
        <div class="div3" @click="clickHandler('div3')"></div>
      </div>
    </div>
    <p>once：只执行一次</p>
    <button @click.once="showNum">click</button>
    <p>2. 按键修饰符:按下对应的键才会执行相应的函数</p>
    <p>26个英文字母，up,down,right,left,alt,ctrl...</p>
    <input type="text" @keyup="showKey" v-model="val">
    <p>3. 鼠标修饰符：按下鼠标对应键执行</p>
    <p>.left  .middle  .right</p>
    <div class="div2" @click.middle="shwoClick"></div>
    <p>4. 表单修饰符</p>
    <p>.trim过滤首尾空格，使用场景用户名、密码、昵称</p>
    <input type="text" v-model.trim="val2">
    <p>{{val2}}</p>
    <hr>
    <p>.number只能输入数字，使用场景输入金额、数量</p>
    <input type="text" v-model.number="val3">
    <p>{{val3}}</p>
    <hr>
    <p>.lazy延迟响应.v-model的事件从input变成了change</p>
    <input type="text" v-model.lazy="val4">
    <p>{{val4}}</p>
  </div>
  <script src="../vue.js"></script>
  <script>
    let vm = new Vue({
      el: '#app',
      data: {
        val: '',
        val2: '',
        val3: '',
        val4: '',
      },
      methods: {
        clickHandler(txt) {
          console.log(txt);
        },
        showMenu() {
          console.log('右键了');
        },
        showNum() {
          console.log(6666);
        },
        showKey(e) {
          console.log(e.keyCode);
          console.log('你输入了：', this.val);
        },
        shwoClick() {
          console.log('鼠标点击了');
        }
      },
    })
  </script>
</body>
</html>